package pl.maciejziarko.mshare.utils;

/**
 * @author Maciej Ziarko
 */
public final class Check {
    
    protected Check() {
        throw new AssertionError();
    }
    
    public static void notNull(Object object) {
        if (isNull(object)) {
            throw new IllegalArgumentException();
        }
    }
    
    public static void notNull(Object object, String message) {
        if (isNull(object)) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void notNull(Object object, String message, Object arg1) {
        if (isNull(object)) {
            throw new IllegalArgumentException(
                    FormattedApplicationException.format(message, arg1)
            );
        }
    }

    public static void notNull(Object object, String message, Object arg1, Object arg2) {
        if (isNull(object)) {
            throw new IllegalArgumentException(
                    FormattedApplicationException.format(message, arg1, arg2)
            );
        }
    }
    
    public static void notEmpty(String string) {
        if (empty(string)) {
            throw new IllegalArgumentException();
        }
    }

    public static void notEmpty(String string, String message) {
        if (empty(string)) {
            throw new IllegalArgumentException(message);
        }
    }
    
    public static void notEmpty(String string, String message, Object arg1) {
        if (empty(string)) {
            throw new IllegalArgumentException(
                    FormattedApplicationException.format(message, arg1)
            );
        }
    }
    
    public static void notEmpty(String string, String message, Object arg1, Object arg2) {
        if (empty(string)) {
            throw new IllegalArgumentException(
                    FormattedApplicationException.format(message, arg1, arg2)
            );
        }
    }

    private static boolean empty(String string) {
        return string == null || string.isEmpty();
    }
    
    private static boolean isNull(Object object) {
        return object == null;
    }
    
}
